iT邦幫忙

2024 iThome 鐵人賽

DAY 7
0

今天來解YKL07(UVA11461):Square Numbers

Square Numbers

https://ithelp.ithome.com.tw/upload/images/20240921/20155574G3tHV2Ov62.png

找出a~b之間,開完更號還是int的數字
output有幾個

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) {
        if (a == 0 && b == 0) {
            break;
        }
        int count = 0;
        for (int i = a; i <= b; i++) {
            double root = sqrt(i); 
            if (root == int(root)) { 
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}


上一篇
CPE C++ 刷題 Day 6
下一篇
CPE C++ 刷題 Day 8
系列文
CPE C++ 刷題20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言